<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>写入</h1>
    <input type="text" class="input">
    <button onclick="add()">写入</button>
    <script>
        function add() {
            let x = document.getElementsByClassName('input')[0].value
            const xhr = new XMLHttpRequest()
            xhr.open('post', 'http://127.0.0.1:3000/write')
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            xhr.send(`data=${x}`)
            xhr.onload = (data) => {
                console.log(data.currentTarget.response);
            }
            xhr.onerror = (error) => {
                console.log(error);
            }

        }
    </script>
</body>

</html>